

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetOtherActivities]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[GetOtherActivities]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/******************************************************************
* Name:			GetOtherActivities
* Purpose:		Returns 1 if the user has other activities (staffed on a protocol or tied to agreements)
*
* PARAMETERS
* Name    		Description					
* -------------  	-------------------------------------------
* @admPersonId		AdmPerson Id		
******************************************************************/

CREATE Procedure [dbo].[GetOtherActivities] (
	@admPersonId INTEGER
)
AS
BEGIN

	SET NOCOUNT ON
	
	DECLARE @isStaffed bit 
	DECLARE @hasAgreements bit 
	SET @isStaffed = 0
	SET @hasAgreements = 0

	If Exists (SELECT Id from protocolstaff_map where admpersonid = @admPersonId and IsCurrent = 1) 
	begin
		set @isStaffed = 1
	end
	if Exists(SELECT Agr.Id FROM AgrAgreement Agr
					INNER JOIN SvcEntity SE ON SE.Id = Agr.SvcEntityId
					INNER JOIN SvcEntity_AdmStaffedPerson_Map Map ON Map.SvcEntityId = SE.Id
					WHERE Map.AdmPersonId = @admPersonId 
						AND Agr.IsCurrent = 1)
	begin
		set @hasAgreements = 1
	end

	select (@isStaffed | @hasAgreements)

	
END
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF






